package com.panshi.utils;

import com.panshi.entity.SysEssayCheckT;
import com.panshi.service.ZxClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Service
public class ZxInfo {

    @Autowired
    private ZxClientService zxClientService;

    public void initialize(HttpServletRequest request, Model model, HttpSession session, String statr){
        Object pa = session.getAttribute("page"+statr);
        if(pa==null){
            pa = 1;
        }
        int page = (int)pa;

        String type = request.getParameter("type");
        if(type!=null){
            if(type.equals("up")){
                page -=1;
            }else if(type.equals("wn")){
                page +=1;
            }
        }
        String state = request.getParameter("state");   //状态
        String essayTitle = request.getParameter("essayTitle");
        if(state!=null){
            if(state.equals("咨询状态")){
                state = "";
            }else if(state.equals("未审核")){
                state = "2";
            }else if(state.equals("未通过")){
                state = "3";
            }else if(state.equals("通过")){
                state = "1";
            }
        }

        if(page<1){
            page=1;
        }

        if(state==null || state.equals("")){
            state="-1";
        }
        if(essayTitle==null || essayTitle.equals("")){
            essayTitle="-1";
        }

        System.out.println(essayTitle+" "+state+" "+page);

        List<SysEssayCheckT> sysEssayCheckTS = zxClientService.secLikeState(essayTitle, state, page, 5);

        List<SysEssayCheckT> sysEssayCheckTS1 = zxClientService.secAll();
        model.addAttribute("secSum",sysEssayCheckTS1.size());

        sysEssayCheckTS.forEach(System.out::println);
        session.setAttribute("page"+statr,page);
        model.addAttribute("sysEssayCheckTS",sysEssayCheckTS);
    }
}
